﻿Imports util
Imports System.Data.OleDb

Public Class DepartamentoService
    Public Function findAll() As List(Of Departamento)
        Dim lista As New List(Of Departamento)

        Dim con = contexto.conBD
        Try
            Dim cmd As New OleDbCommand()
            cmd.Connection = con
            con.Open()

            Dim sql As String = "select * from Dpto"
            cmd.CommandText = sql
            Dim dr As OleDbDataReader = cmd.ExecuteReader()
            While dr.Read
                Dim dpto As New Departamento
                dpto.codigo = dr("ccdd").ToString()

                If dpto.codigo <> "00" Then ' excepto departamento 00
                    dpto.nombre = dr("nombreDD").ToString()
                    lista.Add(dpto)
                End If
            End While

        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            con.Close()
        End Try

        Return lista
    End Function
End Class
